package com.gxy.learn.design.model.behaviour.observer.jdk;

import lombok.extern.slf4j.Slf4j;

import java.util.Observable;
import java.util.Observer;

/**
 * @description: 观察者角色
 * @author: gaoxueyong
 * @Date: 2022/11/8 20:00
 */
@Slf4j
public class Police implements Observer {
    private String name;

    public Police(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    /**
     * This method is called whenever the observed object is changed. An
     * application calls an <tt>Observable</tt> object's
     * <code>notifyObservers</code> method to have all the object's
     * observers notified of the change.
     *
     * @param o   the observable object.
     * @param arg an argument passed to the <code>notifyObservers</code>
     */
    @Override
    public void update(Observable o, Object arg) {
        Thief thief = (Thief) o;
        log.info("{}(警察)：{}(小偷),我已经盯你很久了，你可以保持沉默，但你所说的每一句话都将成为呈堂证供！",this.name,thief.getName());
    }
}
